package com.jie.langlangmall.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.model.SmsFlashPromotion;
import com.jie.langlangmall.service.SmsFlashPromotionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/26
 * @Email 3217998214@qq.com
 * @Description 限时购活动管理
 */
@RestController
@Tag(name = "SmsFlashPromotionController", description = "限时购活动管理")
@RequestMapping("/flash")
public class SmsFlashPromotionController {

    @Autowired
    private SmsFlashPromotionService flashPromotionService;

    @Operation(summary = "添加秒杀活动")
    @PostMapping("/create")
    public CommonResult<?> create(@RequestBody SmsFlashPromotion flashPromotion) {
        flashPromotionService.create(flashPromotion);
        return CommonResult.success();
    }

    @Operation(summary = "修改活动")
    @PostMapping("/update/{id}")
    public CommonResult<?> update(@PathVariable("id") Long id, @RequestBody SmsFlashPromotion flashPromotion) {
        flashPromotionService.update(id, flashPromotion);
        return CommonResult.success();
    }

    @Operation(summary = "删除活动")
    @PostMapping("/delete/{id}")
    public CommonResult<?> delete(@PathVariable Long id) {
        flashPromotionService.delete(id);
        return CommonResult.success();
    }

    @Operation(summary = "修改上线、下线状态")
    @PostMapping("/update/status/{id}")
    public CommonResult<?> updateStatus(@PathVariable("id") Long id, @RequestParam("status") Integer status) {
        flashPromotionService.updateStatus(id, status);
        return CommonResult.success();
    }

    @Operation(summary = "获取详情")
    @GetMapping("/{id}")
    public CommonResult<SmsFlashPromotion> getItem(@PathVariable("id") Long id) {
        SmsFlashPromotion flashPromotion = flashPromotionService.getItem(id);
        return CommonResult.success(flashPromotion);
    }

    @Operation(summary = "分页查询")
    @GetMapping("/list")
    public CommonResult<CommonPage<SmsFlashPromotion>> list(@RequestParam(value = "keyword", required = false) String keyword,
                                                            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<SmsFlashPromotion> flashPromotionList = flashPromotionService.list(keyword, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(flashPromotionList));
    }
}
